<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

$msg = array();

//权限验证
if( Role::init() == false ){
	$msg['error'] = false;
	$msg['string'] = '权限不足！';
	$myjson = json_encode($msg); 
	echo $myjson; 
	exit;
}

$db = new DB('news');

$title_id = isset($_POST['title_id']) ? h($_POST['title_id']) : '';

if($title_id==''){//id不存在
	$msg['error'] = false;
	$msg['string'] = '参数有误！';
}else{
	$news_sql = 'select index_top,category_id,title_id,title from news where title_id="'.$title_id.'"';
	$news_rs = $db->query($news_sql)->getOne();
	
	if($news_rs['index_top'] == 1){
		$index_top = 2;
		$msg['string'] = '已置顶';
		
		$log_status = 11;
	}else{
		$index_top = 1;
		$msg['string'] = '置顶';
		
		$log_status = 13;
	}
	$data=array('index_top'=>$index_top);
	$db->table('news')->where('title_id="'.$title_id.'"')->update($data)->run();
	$msg['error'] = true;

	//记录动作日志
	Log::logs_articles($news_rs['category_id'], $log_status, $news_rs['title_id'], $news_rs['title']);

}
$myjson = json_encode($msg); 
echo $myjson; 
exit;